
import java.text.DecimalFormat;
import java.util.Scanner;

/**
 * 链式多项式相加
 * 2  1 2.4  0 3.2
 * 2  2 1.5  1 0.5
 */

public class E_1002 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        double[] a = new double[1001];

        for(int i = 0; i < t; i++) {
            a[in.nextInt()]=in.nextDouble();
        }

        t = in.nextInt();
        for(int i = 0; i < t; i++) {
            a[in.nextInt()] += in.nextDouble();
        }

        StringBuilder sb = new StringBuilder();
        int num=0;
        for(int i = 0; i < 1001; i++) {
            if(a[i] != 0) {
                num++;
            }
        }
        sb.append(num + " ");

        DecimalFormat df = new DecimalFormat("0.0");
        for(int i = 1000; i >= 0; i--) {
            if(a[i] != 0) {
                sb.append(i).append(" ").append(df.format(a[i])).append(" ");
            }
        }
        sb.deleteCharAt(sb.length() - 1);
        System.out.println(sb);
    }

}
